﻿
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using TomanuExtensions;
using System.Reflection;
using System.Linq;
using TomanuExtensionsTest.TestClasses;

namespace TomanuExtensionsTest
{
    [TestClass()]
    public class PropertyInfoExtensions_Virtual_Abstract_Normal_Overriden
    {
        [TestMethod()]
        public void PropertyInfoExtensions_Abstract_Normal_Overriden_Virtual()
        {
            var pac = typeof(AC).GetProperties(
                        BindingFlags.Instance | BindingFlags.Public |
                        BindingFlags.NonPublic);

            var pbc = typeof(BC).GetProperties(
                BindingFlags.Instance | BindingFlags.Public |
                BindingFlags.NonPublic);

            // Abstrakcyjne.
            var pc1 = (from p in pac.Concat(pbc)
                       where p.IsAbstract()
                       select p).ToArray();

            // Wirtualne.
            var pc2 = (from p in pac.Concat(pbc)
                       where p.IsVirtual()
                       select p).ToArray();

            // Nadpisane.
            var pc3 = (from p in pac.Concat(pbc)
                       where p.IsOverriden()
                       select p).ToArray();

            var pac1a = pc1.Select(p => p.Name + "_" + p.DeclaringType.Name).
                OrderBy(s => s).ToArray();
            var pac2a = pc2.Select(p => p.Name + "_" + p.DeclaringType.Name).
                OrderBy(s => s).ToArray();
            var pac3a = pc3.Select(p => p.Name + "_" + p.DeclaringType.Name).
                OrderBy(s => s).ToArray();

            var t1 = new string[] { "G_AC", "H_AC", "IPA_AC", "IPA2_AC" };
            var t2 = new string[] { "E2_BC", "F3_BC", "IP_AC", "IP_AC", "IP1_AC", "IP1_BC", 
                                    "IP2_BC", "IPV_AC", "IPV_AC", "IPV1_AC", "IPV1_BC", 
                                    "IPV2_AC", "IPV2_BC", "IPV3_BC", "J_AC", "K_AC", "L_AC", 
                                    "L_AC", "M_AC", "M_AC", "P_AC", "P_BC", "Q_AC", "R_AC", 
                                    "R_BC", "S_AC", "T_BC", "U_BC" };
            var t3 = new string[] { "G_BC", "H_BC", "IPA_BC", "IPA2_BC", "J_BC", "K_BC" };

            CollectionAssert.AreEqual(pac1a, t1);
            CollectionAssert.AreEqual(pac2a, t2);
            CollectionAssert.AreEqual(pac3a, t3);
        }
    }
}
